package com.payment.channel.util;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;

import com.fast.common.util.ApplicationUtil;

public class WechatUtil {

	public static String getRedirectUrl() {
		StringBuilder sbufer = new StringBuilder();
		sbufer.append("https://open.weixin.qq.com/connect/oauth2/authorize?");
		sbufer.append("appid=");
		sbufer.append(Configure.getAppid());
		sbufer.append("&redirect_uri=");
		String url = ApplicationUtil.getValue("wxpay.redirectUrl");
		try {
			sbufer.append(URLEncoder.encode(url, "UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		sbufer.append("&response_type=code");
		sbufer.append("&scope=snsapi_base");
		sbufer.append("&state=123");
		sbufer.append("#wechat_redirect");
		return sbufer.toString();
	}

	public static String getOpenIdUrl(String code) {
		StringBuilder sbufer = new StringBuilder();
		sbufer.append("https://api.weixin.qq.com/sns/oauth2/access_token?");
		sbufer.append("appid=wxcb4a05cc38537fc5");
		sbufer.append("&secret=73c8ce2a453381c680ebf8401e82a6a4");
		sbufer.append("&code=");
		sbufer.append(code);
		sbufer.append("&grant_type=authorization_code");
		return sbufer.toString();
	}
}
